﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import net.wooga.pets.events.*;
    import net.wooga.pets.models.world.vos.*;
    import net.wooga.pets.models.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.fountain.*;
    import net.wooga.pets.models.world.*;

    public class ShowTutorialCommand extends Command {

        public var tutorialModel:TutorialModel;
        public var gameStateModel:GameStateModel;
        public var event:InfoEvent;
        public var world:WorldModel;
        public var symbolModel:SymbolModel;
        public var userModel:UserModel;
        public var worldModel:WorldModel;

        override public function execute():void{
            var _local1:int;
            l(("execute: " + this.execute));
            if (!this.userModel.isVisitFriendsMode()){
                _local1 = int(this.event.info.state);
                if (_local1 == TutorialModel.FOUNTAIN_START_TUTORIAL_ELDER){
                    this.tutorialModel.state = this.handleFountainStartState(_local1);
                };
            };
        }
        private function handleFountainStartState(_arg1:int):int{
            var _local3:ITreatable;
            var _local2:int = _arg1;
            if (this.isFountainRoomBuilt()){
                _local3 = ITreatable(this.event.info.patient);
                if (_local3.state == WorldConstants.ILL){
                    if (this.worldModel.getRoomById(_local3.roomId).type == GameConstants.TYPE_RECEPTION){
                        _local2 = TutorialModel.FOUNTAIN_WELCOME_ELDER;
                    };
                } else {
                    _local2 = TutorialModel.FOUNTAIN_CLICK_ON_ELDER;
                    if (this.hasAllSymbols()){
                        _local2 = TutorialModel.FOUNTAIN_ZOOM_TO_ELDER;
                    } else {
                        if (this.isOldTreatmentFinished()){
                            _local2 = TutorialModel.FOUNTAIN_RELEASE_ELDER;
                        };
                    };
                };
            };
            return (_local2);
        }
        private function isFountainRoomBuilt():Boolean{
            var _local1:Array = this.world.getRoomIdsOfType(GameConstants.TYPE_FOUNTAIN);
            return ((_local1.length > 0));
        }
        private function hasAllSymbols():Boolean{
            var _local2:TreatmentVO;
            var _local1:ITreatable = ITreatable(this.event.info.patient);
            if (((_local1) && ((_local1.diseaseName == WorldConstants.DISEASE_OLD)))){
                _local2 = _local1.treatments[0];
                if (((_local2) && (_local2.symbols))){
                    return (this.symbolModel.hasSymbols(_local2.symbols));
                };
            };
            return (false);
        }
        private function isOldTreatmentFinished():Boolean{
            var _local1:ITreatable = ITreatable(this.event.info.patient);
            if (((((_local1) && (_local1.currentTreatment))) && ((_local1.diseaseName == WorldConstants.DISEASE_OLD)))){
                return (_local1.currentTreatment.isFinished);
            };
            return (false);
        }

    }
}//package net.wooga.pets.controllers 
